#!/bin/sh /etc/rc.common

START=60

USE_PROCD=1
PROG=/usr/bin/statsd_exporter
CONFFILE=/etc/prometheus-statsd-exporter.yml

start_service() {
	local web_listen_address
	local web_telemetry_path
	local statsd_listen_udp
	local statsd_listen_tcp
	local statsd_mapping_config
	config_load "prometheus-statsd-exporter"
	config_get web_listen_address main web_listen_address "127.0.0.1:9102"
	config_get web_telemetry_path main web_telemetry_path "/metrics"
	config_get statsd_listen_udp main statsd_listen_udp "127.0.0.1:9125"
	config_get statsd_listen_tcp main statsd_listen_tcp "127.0.0.1:9125"
	config_get statsd_mapping_config main statsd_mapping_config "$CONFFILE"

	procd_open_instance
	procd_set_param command "$PROG"
	procd_append_param command --web.listen-address="$web_listen_address"
	procd_append_param command --web.telemetry-path="$web_telemetry_path"
	procd_append_param command --statsd.listen-udp="$statsd_listen_udp"
	procd_append_param command --statsd.listen-tcp="$statsd_listen_tcp"
	procd_append_param command --statsd.mapping-config="$statsd_mapping_config"
	procd_append_param command --log.level="warn"
	procd_set_param file "$config_file"
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_set_param respawn
	procd_close_instance
}
